﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace CPPEI.Coolzon.Designer.Views
{
    [ValueConversion(typeof(DateTime), typeof(string))]
    public class DateTimeToString : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (((DateTime)value) == DateTime.MinValue)
            {
                return "";
            }
            else
            {
                return ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss");
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime dateTime;
            if (DateTime.TryParse(System.Convert.ToString(value), out dateTime))
            {
                return dateTime;
            }
            return DateTime.MinValue;
        }
    }
}
